﻿using System;

namespace CSW.Framework.Common.Binding
{
    /// <summary>
    /// DependsOn attribute.  Add this attribute to a CheckConstraint method (see <see cref="BindableObject.AddCheckConstraint" />
    /// and <see cref="CheckConstraintDelegate" />) to have the constraint rechecked when the property (as passed to the 
    /// constructor of DependsOn) changes.  Any properties that are used in the determination of the success of the check
    /// constraint should be added as DependsOn attributes to ensure the constraint is rechecked.  If the DependsOn is left off,
    /// the constraint will still be checked before saving, however real time updates via <see cref="BindableObject.InvalidData" />
    /// will not occur when a dependency changes.
    /// </summary>
    [AttributeUsage(AttributeTargets.Method | AttributeTargets.Property, AllowMultiple = true)]
    public class DependsOnAttribute : Attribute
    {
        private readonly string m_PropertyName;

        /// <summary>
        /// Initializes a new instance of the <see cref="DependsOnAttribute"/> class.
        /// </summary>
        /// <param name="propertyName">Name of the property.</param>
        public DependsOnAttribute(string propertyName)
        {
            m_PropertyName = propertyName;
        }

        /// <summary>
        /// Gets the name of the property.
        /// </summary>
        /// <value>The name of the property.</value>
        public string PropertyName
        {
            get { return m_PropertyName; }
        }
    }
}
